package model.agent

class AgentInitializer {

	String script = ""

	def path = ""

	Random rnd

	GroovyShell shell

	Binding binding

	def AgentInitializer(path){
		binding = new Binding();
		Random rnd = new Random(1)

		def random = { rnd.nextFloat() }

		binding.setVariable("random", random)

		shell = new GroovyShell(binding);
		
		script = new File(path).text
		//println script
	}

	def init(Agent a){
		shell.evaluate(script)
		
		a.prop.each{name,value ->
			
			a."$name" = binding.getVariable(name)
			//println value
		}
		
		return a
	}
}
